/*
    同时处理多个信号
*/
#include <stdio.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void intermithandler(int signumber);
void continuehandler(int signumber);
void terminatehandler(int signumber);

int main(int argc, char * argv[]) {
    char buffer1[100], buffer2[100];
    int i;
    if(signal(SIGINT, &terminatehandler) == SIG_ERR) {
        fprintf(stdout, "%s\n", "Couldn't register signal handler for SIGINT.");
    }

    if(signal(SIGTSTP, &terminatehandler) == SIG_ERR) {
        fprintf(stdout, "%s\n", "Couldn't register signal handler for SIGTSTP.");
    }

    if(signal(SIGTERM, &terminatehandler) == SIG_ERR) {
        fprintf(stdout, "%s\n", "Couldn't register signal handler for SIGTERM.");
    }

    fprintf(stdout, "Pid of This Process : %6d.\n", getpid());

   for( ; ;) {
        fgets(buffer1, sizeof(buffer1), stdin);
        for(i=0; i<strlen(buffer1); i++) {
            buffer2[i] = buffer1[i] >= 'a' ? buffer1[i] - 32 : buffer1[i];
        }
        fprintf(stdout, "You input is : %s\n\n", buffer2);
    }

    return 0;
}

void intermithandler(int signumber) {
    fprintf(stdout, "Catch signal %d.\n", signumber);
}

void continuehandler(int signumber) {
    fprintf(stdout, "%s\n", "Continue code.");
}

void terminatehandler(int signumber) {
    fprintf(stdout, "Signal SIGTERM.\n");
    exit(0);
}
